package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.enums.FileStatus;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.FileDao;
import io.renren.modules.generator.entity.FileEntity;
import io.renren.modules.generator.service.FileService;


@Service("fileService")
public class FileServiceImpl extends ServiceImpl<FileDao, FileEntity> implements FileService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FileEntity> page = this.page(
                new Query<FileEntity>().getPage(params),
                new QueryWrapper<FileEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public IPage<Map<String, Object>> selectFileList(Page<Map<String, Object>> page, Map<String, Object> params) {
        return baseMapper.selectFileList(page, params);
    }

    @Override
    public IPage<Map<String, Object>> selectDeleteFileList(Page<Map<String, Object>> page, Map<String, Object> params) {
        return baseMapper.selectDeleteFileList(page, params);
    }

    @Override
    public void reclaim(Integer fileId) {
        baseMapper.reclaim(fileId);
    }

    @Override
    public void updateFie(FileEntity fileEntity) {
        baseMapper.updateFie(fileEntity);
    }

    @Override
    public IPage<Map<String, Object>> selectRestoreFileList(Page<Map<String, Object>> page, Map<String, Object> params) {
        return baseMapper.selectRestoreFileList(page, params);
    }

    @Override
    public List<FileEntity> fileListDir(Integer dirId) {
        QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("dir_id", dirId);
        wrapper.eq("is_restore", FileStatus.NORESTORE.getStatus());
        wrapper.eq("is_delete", FileStatus.NORMAL.getStatus());
        return baseMapper.selectList(wrapper);

    }

}
